<?php $this->beginBlock('title');?>
添加分类
<?php $this->endBlock();?>
<?php $this->params['breadcrumbs'] =
    [
        [
            'label' => '添加分类',
//            'url' => \yii\helpers\Url::to(['admin/category/add']),
            'class' => 'active',
        ]
    ];
?>
<div class="row">
    <div class="col-md-12">
        <div class="block-flat">
            <div class="header">
                <h4>添加分类</h4>
            </div>
            <div class="content">
                <form id="sortData" class="form-horizontal group-border-dashed" style="border-radius: 0px;">
                    <input type="hidden" name="pid" value="<?php echo !empty($pInfo['id']) ? $pInfo['id'] : 0;?>">
                    <input type="hidden" name="id" value="<?php echo !empty($cate['id']) ? $cate['id'] : ''?>">
                    <input name="<?= Yii::$app->request->csrfParam;?>" type="hidden" value="<?= Yii::$app->request->csrfToken ?>">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">上级分类</label>
                        <div class="col-sm-9">
                            <input type="text" value="<?php echo !empty($pInfo['name']) ? $pInfo['name'] : '根目录';?>" class="form-control" readonly="true">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">分类名称</label>
                        <div class="col-sm-9">
                            <input type="text" name="name" value="<?php echo !empty($cate['name']) ? $cate['name'] : ''?>" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">分类描述</label>
                        <div class="col-sm-9">
                            <textarea name="desc" class="form-control"><?php echo !empty($cate['desc']) ? $cate['desc'] : ''?></textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button onclick="saveInfo.saveData()" type="button" class="btn btn-primary"><i class="fa fa-save"></i>保存</button>
                            <button onclick="history.go(-1);" class="btn btn-default"><i class="fa fa-mail-reply"></i>返回</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?php $this->beginBlock('footerJsText')?>
    <script>

        var saveInfo = {
            saveData:function () {
                var data = $("#sortData").serialize();
                ajaxLock = false;
                if (ajaxLock)return false;
                ajaxLock = true;
                $.ajax({
                    type:'POST',
                    dataType:'json',
                    data:data,
                    url:'<?php echo \yii\helpers\Url::to(['admin/category/save'])?>',
                    success:function (resp) {
                        layer.msg(resp.m);
                    },
                    error:function () {
                        console.log("save失败");
                    }
                });
            }
        };
    </script>
<?php $this->endBlock()?>